package Plate;

import java.lang.reflect.Array;
import java.sql.SQLOutput;
import java.util.*;

public class Doudizhu {
    private List<Card> pukes = new ArrayList<>();
    private List<Card> player1 = new ArrayList<>();
    private List<Card> player2 = new ArrayList<>();
    private List<Card> player3 = new ArrayList<>();
    private List<Card> base = new ArrayList<>();
    private List<Card> list = new ArrayList();

    public List<Card> getPukes() {
        return pukes;
    }

    public void setPukes(List<Card> pukes) {
        this.pukes = pukes;
    }

    public List<Card> getPlayer1() {
        return player1;
    }

    public void setPlayer1(List<Card> player1) {
        this.player1 = player1;
    }

    public List<Card> getPlayer2() {
        return player2;
    }

    public void setPlayer2(List<Card> player2) {
        this.player2 = player2;
    }

    public List<Card> getPlayer3() {
        return player3;
    }

    public void setPlayer3(List<Card> player3) {
        this.player3 = player3;
    }

    public List<Card> getBase() {
        return base;
    }

    public void setBase(List<Card> base) {
        this.base = base;
    }

    public List<Card> getList() {
        return list;
    }

    public void setList(List<Card> list) {
        this.list = list;
    }

    // 初始化54张扑克牌
    public void init() {
        String[] pai = {"3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"};
        String[] types = "1、2、3、4".split("、");
        for (int i = 0; i < pai.length; i++) {
            for (int j = 0; j < types.length; j++) {
                list.add(new Card(pai[i] + "_", types[j], i, j));
            }
        }
        list.add(new Card("16_1", "", 14, 0));
        list.add(new Card("17_1", "", 13, 0));
        System.out.println(list);
    }

    // 洗牌
    public void xipai() {
        Collections.shuffle(list);
        System.out.println(list);
    }

    // 发牌
    public void fapai() {
         player1 = list.subList(0, 17);
         player2 = list.subList(17, 34);
         player3 = list.subList(34, 51);
         base = list.subList(51, 54);

        sort(player1);
        sort(player2);
        sort(player3);


        System.out.println("翠花" + player1);
        System.out.println("熊大" + player2);
        System.out.println("熊二" + player3);
        System.out.println("底牌" + base);


    }

    public void sort(List list) {
        list.sort(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                if (o1.getPointValue() == o2.getPointValue()) {
                    return o1.getTypValue() - o2.getTypValue();
                } else {
                    return o1.getPointValue() - o2.getPointValue();
                }
            }
        });
    }

    public static void main(String[] args) {
        Doudizhu doudizhu = new Doudizhu();
        doudizhu.init();
        doudizhu.xipai();
        doudizhu.fapai();

    }
}
